package com.hospital.managing.information.system.controller;

import com.alibaba.fastjson.JSON;
import com.hospital.managing.information.system.model.Worker;
import com.hospital.managing.information.system.service.IWorkerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/worker")
public class WorkerController {
    @Autowired
    private IWorkerService iWorkerService;

    @GetMapping("/test")
    public String test(Worker worker, ModelMap modelMap) {
        List<Worker> list = iWorkerService.selectWorker();
        modelMap.put("worker", list);
        return "list";
    }

    @GetMapping("test2")
    @ResponseBody
    public String test2() {
        List<Worker> list = iWorkerService.selectWorker();
        return JSON.toJSONString(list);
    }

    @GetMapping("/test3")
    public String test3(int deptnoid, String mname, ModelMap modelMap) {
        Worker worker = new Worker();
        if (deptnoid != 0) {
            worker.setDeptnoid(deptnoid);
        }
        if (!mname.equals("all")) {
            worker.setMname(mname);
        }
        List<Worker> list = iWorkerService.selectWorkerByProId(worker);
        modelMap.put("worker", list);
        return "list";
    }

}